package cn.iocoder.lw.module.core.dal.mysql.device;

import cn.iocoder.lw.framework.common.pojo.PageResult;
import cn.iocoder.lw.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.lw.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.lw.module.core.controller.admin.device.vo.CoreDevicePageReqVO;
import cn.iocoder.lw.module.core.dal.dataobject.device.CoreDeviceDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 核心-设备 Mapper
 *
 * @author Lw源码
 */
@Mapper
public interface CoreDeviceMapper extends BaseMapperX<CoreDeviceDO> {

    default PageResult<CoreDeviceDO> selectPage(CoreDevicePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CoreDeviceDO>()
                .eqIfPresent(CoreDeviceDO::getProjectId, reqVO.getProjectId())
                .likeIfPresent(CoreDeviceDO::getDeviceType, reqVO.getDeviceType())
                .eqIfPresent(CoreDeviceDO::getSpuId, reqVO.getSpuId())
                .likeIfPresent(CoreDeviceDO::getDeviceName, reqVO.getDeviceName())
                .eqIfPresent(CoreDeviceDO::getDeviceCode, reqVO.getDeviceCode())
                .eqIfPresent(CoreDeviceDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CoreDeviceDO::getCreateTime, reqVO.getCreateTime())
                .betweenIfPresent(CoreDeviceDO::getWarrantyStartTime, reqVO.getWarrantyTime())
                .orderByDesc(CoreDeviceDO::getId));
    }

    default List<CoreDeviceDO> selectListByProjectId(Long projectId) {
        return selectList(new LambdaQueryWrapperX<CoreDeviceDO>()
                .eq(CoreDeviceDO::getProjectId, projectId));
    }

    default List<CoreDeviceDO> selectListBySpudId(Long spuId) {
        return selectList(new LambdaQueryWrapperX<CoreDeviceDO>()
                .eq(CoreDeviceDO::getSpuId, spuId));
    }

    default List<CoreDeviceDO> selectListByProjectIds(List<Long> projectIds) {
        return selectList(new LambdaQueryWrapperX<CoreDeviceDO>()
                .in(CoreDeviceDO::getProjectId, projectIds));
    }

    default long selectCountByProjectIdAndStatus(Long projectId, Integer status) {
        return selectCount(new LambdaQueryWrapperX<CoreDeviceDO>()
                .eq(CoreDeviceDO::getProjectId, projectId)
                .eq(CoreDeviceDO::getStatus, status));
    }

}